export default defineEventHandler(async (event) => {
  const { limit = 6 } = getQuery(event)
  
  // 假数据：精选推荐的源码项目
  // 使用 picsum.photos 提供随机占位图片，后期替换为真实图片
  const products = [
    {
      id: '1',
      title: 'Vue3 + Vite 后台管理系统',
      description: '基于 Vue3、Vite、TypeScript、Element Plus 的后台管理系统，包含权限管理、数据可视化等功能',
      price: 299,
      originalPrice: 599,
      cover: 'https://picsum.photos/seed/admin-system/600/400',
      category: 'frontend',
      tags: ['Vue3', 'TypeScript', 'Element Plus'],
      tech: ['Vue3', 'Vite', 'TypeScript', 'Element Plus', 'Pinia'],
      difficulty: 'intermediate',
      rating: 4.8,
      reviews: 128,
      downloads: 1580,
      createdAt: '2025-01-01',
      updatedAt: '2025-01-10',
    },
    {
      id: '2',
      title: 'React18 电商系统全栈项目',
      description: '完整的电商系统，包含用户端、管理后台、支付集成、订单管理等功能',
      price: 499,
      originalPrice: 999,
      cover: 'https://picsum.photos/seed/ecommerce/600/400',
      category: 'fullstack',
      tags: ['React', 'Node.js', 'MongoDB'],
      tech: ['React18', 'Next.js', 'Node.js', 'Express', 'MongoDB'],
      difficulty: 'advanced',
      rating: 4.9,
      reviews: 256,
      downloads: 2340,
      createdAt: '2025-01-05',
      updatedAt: '2025-01-12',
    },
    {
      id: '3',
      title: 'Nuxt3 内容管理系统',
      description: '基于 Nuxt3 的内容管理系统，支持 Markdown、SEO 优化、多语言等功能',
      price: 399,
      originalPrice: 799,
      cover: 'https://picsum.photos/seed/cms/600/400',
      category: 'fullstack',
      tags: ['Nuxt3', 'Vue3', 'TailwindCSS'],
      tech: ['Nuxt3', 'Vue3', 'Nuxt Content', 'TailwindCSS'],
      difficulty: 'intermediate',
      rating: 4.7,
      reviews: 89,
      downloads: 956,
      createdAt: '2025-01-08',
      updatedAt: '2025-01-11',
    },
    {
      id: '4',
      title: 'NestJS + TypeORM 企业级后端',
      description: '企业级 RESTful API 项目，包含认证授权、数据库操作、文件上传等功能',
      price: 599,
      originalPrice: 1299,
      cover: 'https://picsum.photos/seed/backend/600/400',
      category: 'backend',
      tags: ['NestJS', 'TypeScript', 'MySQL'],
      tech: ['NestJS', 'TypeScript', 'TypeORM', 'MySQL', 'Redis'],
      difficulty: 'advanced',
      rating: 4.9,
      reviews: 178,
      downloads: 1876,
      createdAt: '2025-01-03',
      updatedAt: '2025-01-09',
    },
    {
      id: '5',
      title: 'uniapp 跨平台商城小程序',
      description: 'uniapp 开发的跨平台商城，支持微信小程序、H5、App 多端',
      price: 699,
      originalPrice: 1499,
      cover: 'https://picsum.photos/seed/miniapp/600/400',
      category: 'mobile',
      tags: ['uniapp', 'Vue3', '微信小程序'],
      tech: ['uniapp', 'Vue3', '微信小程序', 'uni-ui'],
      difficulty: 'intermediate',
      rating: 4.6,
      reviews: 145,
      downloads: 1234,
      createdAt: '2025-01-06',
      updatedAt: '2025-01-13',
    },
    {
      id: '6',
      title: 'Three.js 3D 可视化大屏',
      description: '基于 Three.js 的 3D 数据可视化大屏，包含粒子效果、动画等',
      price: 799,
      originalPrice: 1599,
      cover: 'https://picsum.photos/seed/3d-screen/600/400',
      category: 'frontend',
      tags: ['Three.js', 'WebGL', '数据可视化'],
      tech: ['Three.js', 'Vue3', 'ECharts', 'WebGL'],
      difficulty: 'advanced',
      rating: 5.0,
      reviews: 67,
      downloads: 789,
      createdAt: '2025-01-10',
      updatedAt: '2025-01-14',
    },
    {
      id: '7',
      title: 'Flutter 跨平台 APP',
      description: 'Flutter 开发的跨平台移动应用，包含完整的用户系统和社交功能',
      price: 899,
      originalPrice: 1899,
      cover: 'https://picsum.photos/seed/flutter-app/600/400',
      category: 'mobile',
      tags: ['Flutter', 'Dart', 'iOS/Android'],
      tech: ['Flutter', 'Dart', 'Firebase', 'GetX'],
      difficulty: 'advanced',
      rating: 4.8,
      reviews: 112,
      downloads: 998,
      createdAt: '2025-01-07',
      updatedAt: '2025-01-12',
    },
    {
      id: '8',
      title: 'React Native 社交 APP',
      description: 'React Native 开发的社交应用，支持聊天、动态、直播等功能',
      price: 999,
      originalPrice: 2199,
      cover: 'https://picsum.photos/seed/rn-social/600/400',
      category: 'mobile',
      tags: ['React Native', 'TypeScript', '社交'],
      tech: ['React Native', 'TypeScript', 'Redux', 'Socket.io'],
      difficulty: 'advanced',
      rating: 4.7,
      reviews: 95,
      downloads: 876,
      createdAt: '2025-01-04',
      updatedAt: '2025-01-11',
    },
  ]
  
  // 根据 limit 返回对应数量
  const limitNum = Number(limit)
  const selectedProducts = products.slice(0, limitNum)
  
  // 为每个产品添加 images 字段
  const items = selectedProducts.map(product => ({
    ...product,
    difficulty: product.difficulty as 'beginner' | 'intermediate' | 'advanced',
    images: [
      product.cover,
      product.cover.replace('/600/400', '/600/400?random=1'),
      product.cover.replace('/600/400', '/600/400?random=2'),
      product.cover.replace('/600/400', '/600/400?random=3'),
    ]
  }))
  
  return {
    code: 200,
    message: 'success',
    data: {
      items,
      pagination: {
        page: 1,
        pageSize: limitNum,
        total: products.length,
        totalPages: Math.ceil(products.length / limitNum)
      }
    }
  }
})
